import 'package:flutter/material.dart';
import 'package:pd_application/pages/home/tab_index/index.dart';
import 'package:pd_application/pages/order/order.dart';

import '../me/index.dart';
import '../order_settlement/index.dart';

List<BottomNavigationBarItem> bottomNavItems = [
  const BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
  const BottomNavigationBarItem(icon: Icon(Icons.category), label: '分类'),
  const BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), label: '购物车'),
  const BottomNavigationBarItem(icon: Icon(Icons.person), label: '我的'),
];

List<Widget> pages = [
  const HomePage(),
  // const CategoryPage(),
  // const Cart
];

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final List<BottomNavigationBarItem> bottomTabs = [
    const BottomNavigationBarItem(
      icon: Icon(Icons.home),
      label: '首页',
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.category),
      label: '订单列表',
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.shopping_cart),
      label: '订单结算',
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.person),
      label: '我的',
    ),
  ];
  final List<Widget> tabBodies = [
    const TabIndex(),
    OrderPage('订单列表'),
    const OrderSettlementPage(),
    const MePage(),
  ];
  int currentIndex = 0;

  void _onItemTapped(int index) {
    setState(() {
      currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: tabBodies[currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        items: bottomTabs,
        currentIndex: currentIndex,
        type: BottomNavigationBarType.fixed,
        onTap: _onItemTapped,
        selectedItemColor: Theme.of(context).primaryColor,
      ),
    );
  }
}
